package com.chukun.disruptor.higher.multi;

import com.chukun.disruptor.higher.chain.Trade;
import com.lmax.disruptor.WorkHandler;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 消费者
 */
public class TradeConsumer implements WorkHandler<Trade> {

    private String consumerID;
    private static AtomicInteger count = new AtomicInteger(0);
    private Random random = new Random();

    public  TradeConsumer(String consumerID){
        this.consumerID = consumerID;
    }

    @Override
    public void onEvent(Trade trade) throws Exception {
        Thread.sleep(random.nextInt(5));
        System.err.println("当前消费者 : "+this.consumerID+" trade info : "+trade.getTradeID());
        count.incrementAndGet();
    }

    public int getCount(){
        return count.get();
    }

}
